package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.Hot_TopicsBean;
import com.ykdl.member.kid.beans.TopicBean;
import com.ykdl.member.kid.circle.TopicAndResultActivity;
import com.ykdl.member.kid.gears.HomeActivity;
import com.ykdl.member.kid.person.PersonCenterActivity;
import com.ykdl.member.kid.util.DateUtil;

public class HotTopicAdapter extends BaseAdapter {
	private ArrayList<Hot_TopicsBean>   list;
	private BitmapUtils bitmapUtil ;
	private Context mContext ;
	public HotTopicAdapter(Context context){
		mContext = context;
		bitmapUtil = new BitmapUtils(context);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defult_head_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_head_icon);
	}
	
	public void setList(ArrayList<Hot_TopicsBean> list) {
		this.list = list;
		
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list==null) {
			return 0;
		}else {
			return list.size();
		}
	
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		 return list.get(arg0-1);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.hot_topics_item, null);
			holder = new ViewHolder();
			holder.head = (ImageView) convertView.findViewById(R.id.user_head);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.views_count = (TextView) convertView
					.findViewById(R.id.views_count);
			holder.conent = (TextView) convertView.findViewById(R.id.conent);
			holder.reply_count = (TextView) convertView.findViewById(R.id.reply_count);
			holder.is_digest = (ImageView) convertView
					.findViewById(R.id.is_digest);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
			holder.name.setText(list.get(position).getActor().getDisplay_name());
			if (list.get(position).getActor().getAvatar_url() != null) {
				String url = list.get(position).getActor().getAvatar_url();
				bitmapUtil.display(holder.head, url);
			} else {
				holder.head.setImageResource(R.drawable.defualt_icon);
			}
			holder.head.setTag(list.get(position));
			holder.head.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Hot_TopicsBean bean=(Hot_TopicsBean)v.getTag();
					Intent intent =new Intent(mContext,TopicAndResultActivity.class);
					 intent.putExtra(TopicAndResultActivity.STR_TOPIC_ID,bean.getTopic_id()+"");
					 intent.putExtra(TopicAndResultActivity.STR_GROUP_ID, bean.getGroup_id()+"");
					 mContext.startActivity(intent);
				}
			});

		
		holder.views_count.setText(list.get(position).getViews_count() + "");
		holder.conent.setText(list.get(position).getTopic_title());
		holder.reply_count.setText(list.get(position).getReplies_count());
		return convertView;
	}
	class ViewHolder {
		ImageView head;
		TextView name;
		TextView group_name;
		TextView views_count;
		TextView conent;
		TextView reply_count;
		ImageView is_digest;
	}
}


